from spargameproject.spargame.game.engine.game_engine import GameBot
from spargameproject.spargame.models import Play

class EasySparBot(GameBot):

  def handleResponse(self, game_engine, game, game_player, play_type):
    cards_left = game_player.getMetadata('cards_left')
    if play_type == 'drop' and cards_left:
      card_to_beat = game.getMetadata('card_to_beat')

      index = None
      for i, card_left in enumerate(cards_left):
        if card_left:
          if card_left.suit == card_to_beat.suit:
            index = i
            break
          elif index is None:
            index = i
      bot_play = Play.objects.create(player=game_player.player, game=game, play_type='drop')
      metadata = {'card_indeces': str(index), 'cards': cards_left[index].fileFormat()}
      bot_play.setMetadataWithMap(metadata)
      return bot_play
    else:
      return None, None

  def getType(self):
    return 'easy'

class MediumSparBot(GameBot):

  def handleResponse(self, game_engine, game, game_player, play_type):
    print "Hi I'm a medium bot!"

  def getType(self):
    return 'medium'

class HardSparBot(GameBot):

  def handleResponse(self, game_engine, game, game_player, play_type):
    print "Hi I'm a hard bot!"

  def getType(self):
    return 'hard'
